package com.vibeplayer.app.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 歌曲数据模型类
 */
public class Song implements Parcelable {
    private long id;
    private String title;
    private String artist;
    private String album;
    private String path;
    private long duration;
    private long albumId;
    
    public Song(long id, String title, String artist, String album, String path, long duration, long albumId) {
        this.id = id;
        this.title = title;
        this.artist = artist;
        this.album = album;
        this.path = path;
        this.duration = duration;
        this.albumId = albumId;
    }

    protected Song(Parcel in) {
        id = in.readLong();
        title = in.readString();
        artist = in.readString();
        album = in.readString();
        path = in.readString();
        duration = in.readLong();
        albumId = in.readLong();
    }

    public static final Creator<Song> CREATOR = new Creator<Song>() {
        @Override
        public Song createFromParcel(Parcel in) {
            return new Song(in);
        }

        @Override
        public Song[] newArray(int size) {
            return new Song[size];
        }
    };
    
    public long getId() {
        return id;
    }
    
    public String getTitle() {
        return title;
    }
    
    public String getArtist() {
        return artist;
    }
    
    public String getAlbum() {
        return album;
    }
    
    public String getPath() {
        return path;
    }
    
    public long getDuration() {
        return duration;
    }
    
    public long getAlbumId() {
        return albumId;
    }
    
    /**
     * 将歌曲时长转换为分钟:秒格式的字符串
     * @return 格式化的时长字符串
     */
    public String getDurationString() {
        long minutes = (duration / 1000) / 60;
        long seconds = (duration / 1000) % 60;
        return String.format("%02d:%02d", minutes, seconds);
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        
        Song song = (Song) o;
        return id == song.id;
    }
    
    @Override
    public int hashCode() {
        return (int) (id ^ (id >>> 32));
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(id);
        dest.writeString(title);
        dest.writeString(artist);
        dest.writeString(album);
        dest.writeString(path);
        dest.writeLong(duration);
        dest.writeLong(albumId);
    }
} 